/**
 * Coryright 2015-2020 www.eyaomall.cn
 * All rights reserved.
 * @author tumingjun
 * @date 2016年9月20日
 *
 */

package com.eyaomall.wxmanage.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.eyaomall.wxmanage.dao.InvoiceDao;
import com.eyaomall.wxmanage.model.po.DepositUser;
import com.eyaomall.wxmanage.model.po.Invoice;
import com.eyaomall.wxmanage.model.vo.InvoiceVO;
import com.eyaomall.wxmanage.service.DepositUserService;
import com.eyaomall.wxmanage.service.InvoiceService;
import com.eyaomall.wxmanage.service.ShopPaymentRecordService;
import com.lycheeframework.core.cmp.kit.PageHTTPObject;
import com.lycheeframework.core.cmp.kit.Pages;

/**
 * @author tumingjun
 *
 */
@Service
public class InvoiceServiceImpl implements InvoiceService{

	@Autowired
	private InvoiceDao invoiceDao;
	
	@Autowired
	private DepositUserService depositUserService;
	
	@Autowired
	private ShopPaymentRecordService shopPaymentRecordService;
	
	
	/**
	 * 分页查询
	 */
	public Pages<?> page_data(InvoiceVO invoiceVO, PageHTTPObject httpObject) {
		
		return invoiceDao.page(invoiceVO, httpObject);
	}

	/**
	 * 拒绝开票
	 */
	public boolean refuse(Integer invoiceId,String memo) {
		
		Invoice invoice = new Invoice();
		invoice.setId(invoiceId);
		invoice.setState("3");
		invoice.setMemo(memo);
		return invoiceDao.update(invoice);
	}
	
	/**
	 * 同意开票
	 */
	public boolean agree(Integer invoiceId) {

		Invoice invoice = new Invoice();
		invoice.setId(invoiceId);
		invoice.setState("2");
		return invoiceDao.update(invoice);
	}
	
	/**
	 * 付款成功修改发票
	 */
	@Transactional(propagation=Propagation.REQUIRED)
	public boolean hasPay(Integer paymentId) {
		
		return shopPaymentRecordService.payment(paymentId+"", "1");
	}

	/**
	 * 根据订单号查询发票
	 */
	public Invoice queryByPaymentId(Integer paymentId) {
		
		return (Invoice) invoiceDao.query("queryByPaymentId",paymentId);
	}

	/**
	 * 修改状态
	 */
	public boolean changState(Integer invoiceId) {
		
		Invoice invoice = new Invoice();
		invoice.setId(invoiceId);
		invoice.setState("1");
		return invoiceDao.update(invoice);
	}

}
